#include "summatordialog.h"
#include <QVBoxLayout>
#include <QHBoxLayout>

SummatorDialog::SummatorDialog(QWidget *parent) :
    QDialog(parent), m_sum(new Summator(this))
{
    m_sum->setA(0);
    m_sum->setB(0);
    QVBoxLayout *vlay = new QVBoxLayout();
    QHBoxLayout *hlay = new QHBoxLayout();
    QHBoxLayout *hlay1 = new QHBoxLayout();
    QHBoxLayout *hlay2 = new QHBoxLayout();
    hlay->addWidget(new QLabel("Sum = ", this));
    m_sumlabel = new QLabel("0", this);
    hlay->addWidget(m_sumlabel);
    vlay->addLayout(hlay);
    hlay1->addWidget(new QLabel("A:", this));
    m_aedit = new QLineEdit("0", this);
    hlay1->addWidget(m_aedit);
    hlay2->addWidget(new QLabel("B:", this));
    m_bedit = new QLineEdit("0", this);
    hlay2->addWidget(m_bedit);
    vlay->addLayout(hlay1);
    vlay->addLayout(hlay2);
    m_button = new QPushButton("Set", this);
    vlay->addWidget(m_button);
    setLayout(vlay);

    connect(m_button, SIGNAL(clicked()), this, SLOT(setValues()));
    connect(m_sum, SIGNAL(valueChanged()), this, SLOT(changeSum()));
}

void SummatorDialog::setValues()
{
    m_sum->setA(m_aedit->text().toInt());
    m_sum->setB(m_bedit->text().toInt());
}

void SummatorDialog::changeSum()
{
    int sum = m_sum->sum();
    m_sumlabel->setText(QString::number(sum));
}
